﻿Imports System.Windows.Forms

Public Class OptionsDialog

    Private _optionspage As New List(Of OptionPage)

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        AddOptionsPage(New FileViewOptionsPage())
        AddOptionsPage(New EditorOptionPage())
        AddOptionsPage(New EditorThemeOptionPage())
    End Sub

    Private Sub OptionsDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Sub OptionTabPages_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionTabPages.SelectedIndexChanged
        Dim optiontab As OptionPage = CType(OptionTabPages.SelectedTab, OptionPage)
        optiontab.OnFocus()
    End Sub

    Private Sub OptionsDialog_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        For Each optionpage In _optionspage
            optionpage.OnLoadSettings()
        Next

        Dim optiontab As OptionPage = CType(OptionTabPages.SelectedTab, OptionPage)
        optiontab.OnFocus()
    End Sub

    Public Sub AddOptionsPage(ByRef optionpage As OptionPage)
        _optionspage.Add(optionpage)
        OptionTabPages.TabPages.Add(optionpage)
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        For Each optionpage In _optionspage
            optionpage.OnApplySettings()
        Next

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

End Class
